package month1;

public class IsValidBST98_05 {
    public static void main(String[] args) {
        System.out.println(isValidBST(new TreeNode(new Integer[]{2147483647})));
    }

    /**
     * 递归查询
     * @param root
     * @return
     */
    static boolean isValidBST(TreeNode root) {
        return isValidBST(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    static boolean isValidBST(TreeNode root, long l, long r) {
        if (root == null) {
            return true;
        }
        return root.val < r && root.val > l && isValidBST(root.left, l, root.val) && isValidBST(root.right, root.val, r);
    }
}
